home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: uu4news.netcom.com!zodiac!szh
- From: szh@zcon.com (Syed Zaeem Hosain)
- Subject: Re: accessing structures via pointers
- Message-ID: <1996Apr10.045928.18797@zcon.com>
- Sender: szh@zcon.com (Syed Zaeem Hosain)
- Nntp-Posting-Host: zodiac
- Reply-To: szh@zcon.com
- Organization: Z Consulting Group
- References: <4kcn32$564@uhura.phoenix.net>
- Date: Wed, 10 Apr 1996 04:59:28 GMT
-
- In article <4kcn32$564@uhura.phoenix.net>, brucew@phoenix.net (Bruce Wedding) writes:
- >In comp.lang.c
- >csyamc@scs.leeds.ac.uk (A M Casey) wrote:
- >
- >> struct group {
- >> char *gr_name; /* the name of the group */
- >> char *gr_passwd; /* the encrypted group password */
- >> gid_t gr_gid; /* the numerical group ID */
- >> char **gr_mem; /* vector of pointers to member names */
- >> };
- >
- >I assume the function is allocating memory for these strings?
- >
- >>printf("the group name is %s\n",tempgroup.gr_name);
- >
- >Try it like this:
- >
- >printf("the group name is %s\n",tempgroup->gr_name);
- >
- >which is an easier way than doing this:
- >
- >printf("the group name is %s\n",*(tempgroup).gr_name);
- ^^^^^^^^^^^^^^^^^^^^
-
- Uhhh ... wouldn't this be (*tempgroup).gr_name rather than what you
- show? Looks like a typo to me. Of course, the first way is much
- more the way to go since it avoids these problems! :-)
-
- Z
-
-
- --
- -------------------------------------------------------------------------
- | Syed Zaeem Hosain P. O. Box 610097 (408) 441-7021 |
- | Z Consulting Group San Jose, CA 95161 szh@zcon.com |
- -------------------------------------------------------------------------
-